home *** CD-ROM | disk | FTP | other *** search
- #include <MacHeaders68K>
-
- #include <String.h>
- #include <Strings.h>
-
- #define NMENUS 3 /* number of defined menus */
- #define appleMenu 256
- #define fileMenu 257
- #define editMenu 258
- #define fileMSize 3 /* size of File menu */
-
- #define DEFAULTNUM 129 /* default resource number */
-
- char done; /* true to exit program */
- char debug_mode; /* debug mode flag */
-
- /* screen control rectangles */
- /* variables for my window */
- MenuHandle myMenus[NMENUS];
- struct EventRecord myEvent;
- char da_menu;
- Rect screenRect; /* rectangle defining screen */
- Rect dragRect; /* rectangle defining bounds for dragging */
- Rect sizeRect; /* rectangle for resizing windows */
- struct Point sfgpoint; /* standard file dialog locations */
- struct Point sfppoint;
-
- void macinit(void);
- void macend(void);
- void hndmac(void);
- void updevent(GrafPtr);
- void menu_upd(void);
- void docommand(long);
- void appl_menu(void);
- void aboutdlg(void);
- void ctrwindow(GrafPtr);
- void framedflt(DialogPtr);
-
- /* In showerr.c: */
- void showerr(char * s);
- void ctralrt(short);
-
- void getinfo(Boolean debug);
-
- void main()
- {
- debug_mode = 0;
- macinit(); /* initialize Mac */
- done = 0;
- while (!done) hndmac(); /* handle Mac events and I/O */
- macend();
- }
-
- void macinit()
- {
- short i, bigscreen;
-
- /* set-up general Macintosh environment */
- MaxApplZone(); /* set-up for efficient storage use */
- for (i=0; i < 4; i++) MoreMasters();
- InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitFonts();
- InitMenus();
- InitDialogs(0L);
- InitCursor();
- TEInit();
-
- /* set-up menus */
- for (i=0; i < NMENUS; i++) {
- myMenus[i] = GetMenu(256+i);
- InsertMenu(myMenus[i], 0);
- }
- AddResMenu(myMenus[0], 'DRVR');
- da_menu = 0;
- appl_menu();
-
- /* center alerts */
- ctralrt(256);
-
- screenRect = qd.screenBits.bounds;
-
- bigscreen = (((screenRect.bottom-screenRect.top) >= 480) &&
- ((screenRect.right-screenRect.left) >= 640));
-
- /* calculate standard file dialog location*/
- sfppoint.h = (screenRect.right-screenRect.left-304)/2;
- sfgpoint.h = (screenRect.right-screenRect.left-348)/2;
- if (bigscreen) {
- sfppoint.v = (screenRect.bottom-screenRect.top-184)/3;
- sfgpoint.v = (screenRect.bottom-screenRect.top-200)/3;
- }
- else {
- sfppoint.v = (screenRect.bottom-screenRect.top-184)/2;
- sfgpoint.v = (screenRect.bottom-screenRect.top-200)/2;
- }
-
- SetRect(&dragRect, 0, 24, screenRect.right-4, screenRect.bottom-4);
-
- SetRect(&sizeRect, 50, 25, screenRect.right+1, screenRect.bottom+1);
- }
-
- void macend()
- {
- }
-
- void hndmac()
- {
- OSErr rc;
- short code;
- GrafPtr gp;
- unsigned short h, w;
- long l;
- WindowPtr whichWindow;
- struct WindowRecord * fw;
- char frontda;
-
- rc = GetNextEvent(everyEvent, &myEvent);
- if (rc == 0) /* FALSE from GNE */
- switch(myEvent.what) {
- case nullEvent:
- fw = (WindowRecord *)FrontWindow();
- frontda = fw->windowKind < 0;
- if (frontda) {
- if (!da_menu) {
- da_menu = 1;
- SetItem(myMenus[1], fileMSize, "\pClose");
- appl_menu();
- }
- }
- else {
- if (da_menu) {
- da_menu = 0;
- SetItem(myMenus[1], fileMSize, "\pQuit");
- appl_menu();
- }
- }
- SystemTask(); /* run DAs, etc. */
- break;
- default:
- return;
- }
- else switch(myEvent.what) { /* TRUE from GNE */
- case mouseDown:
- code = FindWindow(myEvent.where, &whichWindow);
- switch (code) {
- case inMenuBar:
- menu_upd();
- docommand(MenuSelect(myEvent.where));
- break;
- case inSysWindow:
- SystemClick((EventRecord *)&myEvent, whichWindow);
- break;
- case inDrag:
- if (whichWindow == FrontWindow())
- DragWindow(whichWindow, myEvent.where, (Rect *)&dragRect);
- else SelectWindow(whichWindow);
- break;
- case inGoAway:
- break;
- case inGrow:
- if (whichWindow == FrontWindow()) {
- GetPort(&gp);
- SetPort((GrafPtr)whichWindow);
- l = GrowWindow(whichWindow, myEvent.where, (Rect *)&sizeRect);
- h = l >> 16;
- w = l & 0x0000ffffL;
- SizeWindow(whichWindow, w, h, 0x100);
- SetPort(gp);
- }
- break;
- case inContent:
- if (whichWindow != FrontWindow()) {
- SelectWindow(whichWindow);
- break;
- }
- break;
-
- case inZoomIn:
- case inZoomOut:
- if (TrackBox(whichWindow, myEvent.where, code)) {
- if (((WindowPeek)whichWindow)->dataHandle == 0) break;
- GetPort(&gp);
- SetPort((GrafPtr)whichWindow);
- EraseRect(&(((WindowRecord *)whichWindow)->port.portRect));
- ZoomWindow(whichWindow, code, 0);
- SetPort(gp);
- }
- break;
-
- default:
- break;
- }
- break;
-
- case mouseUp:
- break;
-
- case keyDown:
- case autoKey:
- break;
-
- case activateEvt:
- break;
-
- case updateEvt:
- updevent((GrafPtr)myEvent.message);
- break;
-
- case app4Evt:
- break;
-
- default: break;
- }
- }
-
- void updevent(GrafPtr msgptr)
- {
- GrafPtr gp;
-
- GetPort(&gp);
- SetPort(msgptr);
- BeginUpdate(msgptr);
- EndUpdate(msgptr);
- SetPort(gp);
- }
-
- void menu_upd()
- {
- short i;
-
- if (da_menu) {
- for (i = 1; i < fileMSize; i++)
- DisableItem(myMenus[1], i);
- CheckItem(myMenus[1], fileMSize, 0);
- }
- else {
- CheckItem(myMenus[1], fileMSize, done << 8);
- }
- }
-
- void docommand(long mResult)
- {
- register short theItem, theMenu;
- unsigned char name[40];
- WindowRecord * fw;
- short i;
- static char nullstr[1] = {0};
- OSErr readmap();
-
- theMenu = mResult >> 16;
- theItem = mResult & 0xff;
- switch(theMenu) {
- case appleMenu:
- if (theItem == 2) break;
- if (theItem == 1) {
- aboutdlg();
- break;
- }
- GetItem(myMenus[0], theItem, name);
- OpenDeskAcc(name);
- break;
- case fileMenu:
- switch (theItem) {
- case 1:
- debug_mode ^= 1;
- CheckItem(myMenus[1], 1, debug_mode);
- break;
- case 2:
- getinfo(debug_mode);
- break;
- case 3:
- if (!da_menu) {
- done ^= 1;
- break;
- }
- else {
- fw = (WindowRecord *)FrontWindow();
- i = fw->windowKind;
- if (i<0) CloseDeskAcc(i);
- }
- default: break;
- }
- break;
- case editMenu:
- SystemEdit(theItem-1);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- appl_menu();
- }
-
- void appl_menu() /* enable correct application menus */
- {
- static char last_da = 2; /* init to invalid value */
-
- /* skip drawing menu if no changes from last time */
- if (last_da == da_menu) return;
- last_da = da_menu; /* save values for next time */
-
- if (da_menu) {
- EnableItem(myMenus[2], 0);
- }
- else {
- DisableItem(myMenus[2], 0);
- }
- DrawMenuBar();
- }
-
- void aboutdlg()
- {
- DialogPtr dlgptr;
- short itemHit;
- unsigned char **version;
- static unsigned char nullstr[1] = {0};
-
- version = (unsigned char **)GetResource('EINF', 1);
- if (version == 0L) {
- return;
- }
- dlgptr = GetNewDialog(257, (Ptr)0L, (WindowPtr)-1L);
- ctrwindow(dlgptr);
- ParamText(*version, nullstr, nullstr, nullstr);
- ShowWindow(dlgptr);
-
- /* frame the default selection */
- framedflt(dlgptr);
-
- ModalDialog(0L, &itemHit);
- DisposDialog(dlgptr);
- ParamText(nullstr, nullstr, nullstr, nullstr);
- }
-
- void ctrwindow(GrafPtr wp)
- {
- short scrhsize, scrvsize;
- short whsize, wvsize;
-
- scrhsize = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
- scrvsize = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
- whsize = wp->portRect.right-wp->portRect.left;
- wvsize = wp->portRect.bottom - wp->portRect.top;
- MoveWindow(wp, (scrhsize-whsize)/2, (scrvsize-wvsize)/3, 0);
- }
-
- void framedflt(DialogPtr dlgptr)
- {
- short gtype;
- Handle gitem;
- Rect gbox;
- GrafPtr gp;
-
- GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
- GetPort(&gp);
- SetPort(dlgptr);
- PenSize(3,3);
- InsetRect(&gbox, -4, -4);
- FrameRoundRect(&gbox, 16, 16);
- SetPort(gp);
- }
-